#include "hdr.h"
#include "rtthread.h"
#include "board.h"

rt_thread_t hdr_thread;
rt_uint8_t hdr_pin;

rt_uint8_t hdr_on_flag = 0;

static void hdr_thread_entry(void *parameter)
{
    while(1)
    {
        if(hdr_on_flag == 1)
        {
            rt_pin_write(hdr_pin, 0);
            rt_thread_mdelay(1);
            rt_pin_write(hdr_pin, 1);
            rt_thread_mdelay(1);
        }
        rt_thread_mdelay(1);
    }
}


void hdr_init(void)
{
    hdr_pin = rt_pin_get("PB.0");
    // 设置引脚为输出方式
    rt_pin_mode(hdr_pin, PIN_MODE_OUTPUT);

    hdr_thread = rt_thread_create("hdr", hdr_thread_entry, RT_NULL, 1024, 18, 10);
    if (hdr_thread != RT_NULL)
    {
        rt_thread_startup(hdr_thread);
    }
    else
    {
        rt_kprintf("creat task err!\n");
    }

}

void hdr_off(void)
{
    //rt_pin_write(hdr_pin, 1);
    hdr_on_flag = 0;
}

void hdr_on(void)
{
    hdr_on_flag = 1;
//    rt_pin_write(hdr_pin, 0);
//    for(kk = 0; kk < 1000; kk++)
//    {
//        rt_pin_write(hdr_pin, 0);
//        rt_thread_mdelay(1);
//        rt_pin_write(hdr_pin, 1);
//        rt_thread_mdelay(1);
//        rt_pin_write(hdr_pin, 0);
//    }

}
